package com.zzy.singleton.singleton4;

/**
 * 枚举
 * 默认枚举实例的创建是线程安全的，但是枚举中包含的方法需要保证线程安全
 */
public class SingletonTest4 {
    public static void main(String[] args) {
        Singleton instance1 = Singleton.INSTANCE;
        Singleton instance2 = Singleton.INSTANCE;
        System.out.println(instance1 == instance2);
        System.out.println("instance1.hashCode()>>>" + instance1.hashCode());
        System.out.println("instance2.hashCode()>>>" + instance2.hashCode());
        instance1.sayOK();
    }
}

enum Singleton {
    INSTANCE;

    public void sayOK() {
        System.out.println("ok_");
    }
}
